<script>
	export default {
		globalData: {
			// 全局设置状态栏和导航栏高度
			isPad: 0,
			statusBarH: 0,
			customBarH: 0,
			// 配置
			baseUrl: 'https://dc.lesjy.cn',//接口地址
			uploadUrl: 'https://dc.lesjy.cn/api/common/upload',//图片上传地址
			imgUrl: 'https://dc.lesjy.cn',//第三方储存图片链接
		},
		onLaunch: function() {
			console.log('App Launch')
			//#ifdef APP-PLUS
			this.getAppUpdate()
			//#endif
			this.getCommonData()
			uni.getSystemInfo({
				success: (e) => {
					// 设备类型
					let deviceType = e.deviceType
					this.globalData.isPad = deviceType.indexOf('pad') !== -1 ? 1 : 0
					// 获取手机状态栏高度
					let statusBar = e.statusBarHeight
					let customBar
			
					// #ifndef MP
					customBar = statusBar + (e.platform == 'android' ? 50 : 45)
					// #endif
			
					// #ifdef MP-WEIXIN
					// 获取胶囊按钮的布局位置信息
					let menu = wx.getMenuButtonBoundingClientRect()
					// 导航栏高度 = 胶囊下距离 + 胶囊上距离 - 状态栏高度
					customBar = menu.bottom + menu.top - statusBar
					// #endif
			
					// #ifdef MP-ALIPAY
					customBar = statusBar + e.titleBarHeight
					// #endif
			
					// 注意：此方法不支持原生Nvue页面
					// Vue.prototype.statusBarH = statusBar
					// Vue.prototype.customBarH = customBar

					// 支持nvue页面写法（兼容H5/小程序/APP/APP-Nvue）
					this.globalData.statusBarH = statusBar
					this.globalData.customBarH = customBar
				}
			});
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			getAppUpdate() {
				plus.runtime.getProperty(plus.runtime.appid, function (widgetInfo) {
					uni.request({
						url: 'https://dc.lesjy.cn/api/common/update',
						data: {
							version_code: widgetInfo.versionCode,  
							type: uni.getSystemInfoSync().platform
						},
						success: (result) => {
							if (result.data.hasOwnProperty('data')) {
								var data = result.data.data;
								if (data.update == 1 && data.wgt_url) {
									uni.showModal({
										title: "发现新版本",
										content: data.comment,
										success: function (res) {
											if (res.confirm == true) {//当用户确定更新，执行更新
												uni.showLoading({
													title: '更新中……'
												})
												if (data.is_force == 1) {
													plus.runtime.openURL(data.app_url);  
												} else {
													uni.downloadFile({//执行下载
														url: data.wgt_url, //下载地址
														success: (downloadResult) => {//下载成功
															uni.hideLoading();
															if (downloadResult.statusCode == 200) {
																uni.showModal({
																	//title: '',
																	content: '更新成功，确定现在重启吗？',
																	confirmText: '重启',
																	confirmColor: '#387BEF',
																	success: function (res) {
																		if (res.confirm == true) {
																			plus.runtime.install(downloadResult.tempFilePath, {
																				force: true
																			}, function (res) {
																				plus.runtime.restart();
																			});
																		}
																	}
																});
															}
														}
													});
												}
											}
										}
									})
								}  
							}
						},
					});
				});
			},
			// 获取公共数据
			getCommonData() {
				this.$store.dispatch('getCommonData')
			},
		},
	}
</script>


<style lang="scss">
	b{
		color: #058FFB !important;
	}
	/* 页面样式 */
	/* #ifdef H5 */
	@media (min-width: 796px) {
	  // page {
	  //   max-width: 796px;
	  //   margin: 0 auto;
	  // }
	}
	/* #endif */
	/*uveiw */
	@import "uview-ui/index.scss";
	/*每个页面公共css */
	@import './common/style.css';
	@import './common/common.css';
	
	.highlight {
		background: linear-gradient(120deg, rgba(46, 204, 113, 0.2), rgba(46, 204, 113, 0));
		padding: 0 5rpx;
		border-radius: 4rpx;
	}
</style>